//  USMemorialDayView.m
//  us
//
//  Created by karry on 2025/4/25.

#import "USMemorialDayView.h"
#import <Masonry/Masonry.h>

@interface USMemorialDayView()

@property (nonatomic,strong) UIView *c_v;
@property (nonatomic,strong) UIView *c_v0;
@property (nonatomic,strong) UIView *c_v1;
@property (nonatomic,strong) UIImageView *pinImageV;

@end

@implementation USMemorialDayView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupView];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupView];
}

- (void)setupView {
    self.backgroundColor = UIColor.clearColor;
 
    self.c_v = [UIView new];
    self.c_v.backgroundColor = [UIColor clearColor];
    self.c_v.layer.cornerRadius = 20.f;
    self.c_v.layer.masksToBounds = YES;
    [self addSubview:self.c_v];

    self.c_v0 = [UIView new];
    [self.c_v addSubview:self.c_v0];

    self.c_v1 = [UIView new];
    self.c_v1.backgroundColor = [UIColor mi_1_color];
    [self.c_v addSubview:self.c_v1];

    self.titleLab = [UILabel new];
    self.titleLab.textAlignment = NSTextAlignmentCenter;
    self.titleLab.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
    self.titleLab.adjustsFontSizeToFitWidth = YES;
    self.titleLab.numberOfLines = 2;
    [self.c_v0 addSubview:self.titleLab];

    self.contentLab = [UILabel new];
    self.contentLab.font = [UIFont systemFontOfSize:15];
    self.contentLab.textAlignment = NSTextAlignmentCenter;
    self.contentLab.numberOfLines = 2;
    [self.c_v1 addSubview:self.contentLab];

    self.infoLab = [UILabel new];
    self.infoLab.textColor = [[UIColor labelColor] colorWithAlphaComponent:.5];
    self.infoLab.font = [UIFont systemFontOfSize:12];
    [self.c_v1 addSubview:self.infoLab];
    
    self.pinImageV = [[UIImageView alloc] initWithImage:nil];
    [self addSubview:self.pinImageV];
    

    [self makeConstraints];
}

- (void)makeConstraints {
    [self.pinImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(0);
        make.centerX.equalTo(self);
        make.width.height.mas_equalTo(32);
    }];

    [self.c_v mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pinImageV.mas_centerY); // 向上叠点
        make.left.right.bottom.equalTo(self);
    }];

    [self.c_v0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.c_v);
        make.height.mas_equalTo(44);
    }];

    [self.c_v1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.c_v0.mas_bottom);
        make.left.right.bottom.equalTo(self.c_v);
    }];

    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.c_v0).offset(6);
        make.right.equalTo(self.c_v0).offset(-6);
        make.centerY.equalTo(self.c_v0).mas_offset(3);
    }];

    [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.c_v1).offset(6);
        make.right.equalTo(self.c_v1).offset(-6);
        make.centerY.mas_equalTo(self.c_v1).mas_offset(-12);
    }];

    [self.infoLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.c_v1).offset(-8);
        make.centerX.equalTo(self.c_v1);
    }];
}

- (void)setColor:(UIColor *)color {
    _color = color;
    
    self.c_v0.backgroundColor = [color colorWithAlphaComponent:0.5];
    if (self.cover.length > 0) {
        self.pinImageV.image = [UIImage imageNamed:self.cover];
    }else {
        self.pinImageV.image = [UIImage systemImageNamed:@"circle.fill"];
    }
    self.pinImageV.tintColor = color;
    self.titleLab.textColor = [color jk_darkenColor:0.35];
    
}

- (void)setCover:(NSString *)cover {
    _cover = cover;
    if (cover.length == 0) {
        self.pinImageV.image = [UIImage systemImageNamed:@"circle.fill"];
    }else{
        self.pinImageV.image = [UIImage imageNamed:cover];
    }
}

- (void)setDayModel:(USMemorialDayModel *)dayModel {
    _dayModel = dayModel;
    
    self.color = [UIColor jk_colorWithHexString:dayModel.color];
    self.cover = dayModel.coverUrl;

    self.titleLab.text = dayModel.anniversaryName;

    self.infoLab.text = dayModel.dayDescription;

    self.contentLab.attributedText = [dayModel dayAttributeWithFontSize:28];


}
 
@end
